<?php
$themename = "你的企业";
$shortname = "swt";
$himg_dir = get_bloginfo('template_directory');
$sfirst_img = $himg_dir . '/images/howtoslide.png';
$mx_categories_obj = get_categories('hide_empty=0');
$mx_categories = array();
foreach ($mx_categories_obj as $mx_cat) {
	$mx_categories[$mx_cat->cat_ID] = $mx_cat->cat_name;
}
$categories_tmp = array_unshift($mx_categories, "Select a category:","Uncategorized" );
$number_entries = array("Select a Number:","1","2","3","4","5","6","7","8","9","10", "12","14", "16", "18", "20" );
$options = array (


array( "name" => $themename." 设置",
       "type" => "title"),

    array( "name" => "幻灯片设置",
           "type" => "section"),
    array( "type" => "open"),

	array(  "name" => "启用/禁用 幻灯片",
			"desc" => "你可以在网站首页启用幻灯片，幻灯片调用的图像是通过get_post_meta($post->ID,’slide’, true);函数实现的，所以你需要在对应的文章中添加’名称’为’slide’，’值’为图片链接地址的自定义字段。添加方法可参看<a href=\"http://ndqy.com/blog/2012/02/18/976.html#5\" target=\"_blank\">首页幻灯片中图片无法显示的解决办法，第五条</a>",
            "id" => $shortname."_slider",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),

	array( 	"name" => "选择分类目录",
			"desc" => "建议你专门创建一个名为首页幻灯片的分类目录，并创作你想展示的文章，然后回到这里选择该分类目录。",
			"id" => $shortname."_slide_category",
			"std" => "Uncategorized",
			"type" => "select",
			"options" => $mx_categories),

	array(	"name" => "显示文章数量",
			"desc" => "建议不要太多，3至5个即可，否则影响首页打开速度。",
			"id" => $shortname."_slide_count",
			"std" => "1",
			"type" => "select",
			"options" => $number_entries),

    array( "type" => "close"),

    array( "name" => "滚动新闻设置",
           "type" => "section"),
    array( "type" => "open"),

	array(  "name" => "启用/禁用 滚动新闻",
			"desc" => "",
            "id" => $shortname."_scroll",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),

	array( 	"name" => "选择分类目录",
			"desc" => "建议设置成企业最新动态等新闻的分类目录，展示企业最新的情况。",
			"id" => $shortname."_scroll_category",
			"std" => "Uncategorized",
			"type" => "select",
			"options" => $mx_categories),

	array(	"name" => "显示文章数量",
			"desc" => "这个数量可以根据企业需要，自己设置。",
			"id" => $shortname."_scroll_count",
			"std" => "1",
			"type" => "select",
			"options" => $number_entries),


    array( "type" => "close"),


    array( "name" => "特色文章和精选文章的设置",
           "type" => "section"),
    array( "type" => "open"),

    array(  "name" => "启用/禁用　特色文章",
			"desc" => '这个设置显示在滚动新闻下面，可展示选中分类目录中最新的4个文章及该文章中的特色图像。注意！要在文章中添加特色图像。',
            "id" => $shortname."_fcontent",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),


 	array(	"name" => "选择分类目录",
			"desc" => '建议这里选择产品展示，因为是带图片的展示嘛。',
			"id" => $shortname."_featured_category12",
            "type" => "select",
            "std" => "Select A Category",
			"options" => $mx_categories),

    array(  "name" => "启用/禁用　精选文章",
			"desc" => '这个出现在侧边栏的最上方，是通过小图片展示的',
            "id" => $shortname."_fcats",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),


 	array(	"name" => "选择分类目录",
			"id" => $shortname."_featured_category1",
            "type" => "select",
            "std" => "Select A Category",
			"options" => $mx_categories),

			array(	"name" => "选择显示的数量",
			"id" => $shortname."_featured_number1",
            "type" => "select",
            "std" => "Select A Number",
			"options" => $number_entries),

    array( "type" => "close"),

	array(  "name" => "带图像的链接设置",
           "type" => "section"),
    array( "type" => "open"),


	array(  "name" => "顶部468x165图像是否启用",
            "id" => $shortname."_topbanner",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),

    array( "name" => "顶部图像地址",
			"desc" => "注意这是一个 468 x 60 的横幅图像。",
            "id" => $shortname."_hbannermatepami",
            "std" => "http://ndqy.com/imga/ggwz.gif",
            "type" => "text"),

	array("name" => "链接地址",
			"desc" => "点击这个图像后打开的网址",
            "id" => $shortname."_hlink",
            "std" => "http://ndqy.com",
            "type" => "text"),


   	array(  "name" => "是否启用125x125图像",
            "id" => $shortname."_banners",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),

	array("name" => "第一个图像的地址",
			"desc" => "注意这是一个125x125的图像",
            "id" => $shortname."_banner1matepami",
            "std" => $himg_dir."/images/zxcp.gif",
            "type" => "text"),

	array("name" => "链接地址",
			"desc" => "点击这个图像后打开的网址",
            "id" => $shortname."_link1",
            "std" => "http://ndqy.com/themeceshi/?cat=3",
            "type" => "text"),

	array("name" => "第二个图像的地址",
			"desc" => "注意这是一个125x125的图像",
            "id" => $shortname."_banner2matepami",
            "std" => $himg_dir."/images/qydt.gif",
            "type" => "text"),

	array("name" => "链接地址",
			"desc" => "点击这个图像后打开的网址",
            "id" => $shortname."_link2",
            "std" => "http://ndqy.com/themeceshi/?cat=8",
            "type" => "text"),

	array("name" => "第三个图像的地址",
			"desc" => "注意这是一个125x125的图像",
            "id" => $shortname."_banner3matepami",
            "std" => $himg_dir."/images/lxwm.gif",
            "type" => "text"),

	array("name" => "链接地址",
			"desc" => "点击这个图像后打开的网址",
            "id" => $shortname."_link3",
            "std" => "http://ndqy.com/themeceshi/?page_id=25",
            "type" => "text"),

	array("name" => "第四个图像的地址",
			"desc" => "注意这是一个125x125的图像",
            "id" => $shortname."_banner4matepami",
            "std" => $himg_dir."/images/xyfk.gif",
            "type" => "text"),

	array("name" => "链接地址",
			"desc" => "点击这个图像后打开的网址",
            "id" => $shortname."_link4",
            "std" => "http://ndqy.com/themeceshi/?page_id=22",
            "type" => "text"),

    array( "type" => "close"),


	array(  "name" => "百度分享设置",
           "type" => "section"),
    array( "type" => "open"),


	array(  "name" => "启用/禁用　百度分享",
			"desc" => "如果启用，则在文章正文下方调用百度分享。",
            "id" => $shortname."_follow",
            "type" => "select",
            "std" => "Display",
            "options" => array("Display", "Hide")),

    array( "type" => "close"),


	array(  "name" => "首页显示文章设置",
            "type" => "section"),
    array( "type" => "open"),

	array(  "name" => "禁用/启用　首页显示文章",
			"desc" => "<font color=\"#ff0000\">注意！如果禁用</font>则首页只显示置顶文章，当有多篇置顶文章时，先发表的在上方（非常适合企业用户），所以这里默认的是禁用。",
			"id" => $shortname."_twidget",
            "type" => "select",
            "std" => "Hide",
            "options" => array("Display", "Hide")),

    array(  "name" => "显示文章数量",
            "id" => $shortname."_num_of_tweets",
            "std" => "5",
            "desc" => "当设置为启用时，请填写首页中显示的数量。首页中实际显示文章数量为置顶文章数量加上你所填的文章数量。博文按正常的习惯顺序，即设置文章在上，普通文章在下。同类文章是最新的文章在上，先发表的在下。",
            "type" => "text"),

    array( "type" => "close"),


);

function mytheme_add_admin() {

global $themename, $shortname, $options;

if ( $_GET['page'] == basename(__FILE__) ) {

	if ( 'save' == $_REQUEST['action'] ) {

		foreach ($options as $value) {
		update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }

foreach ($options as $value) {
	if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }

	header("Location: admin.php?page=themeoptions.php&saved=true");
die;

}
else if( 'reset' == $_REQUEST['action'] ) {

	foreach ($options as $value) {
		delete_option( $value['id'] ); }

	header("Location: admin.php?page=themeoptions.php&reset=true");
die;

}
}

      add_theme_page($themename." 设置", "$themename 设置", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}

function mytheme_add_init() {

$file_dir=get_bloginfo('template_directory');
wp_enqueue_style("functions", $file_dir."/includes/admin/functions.css", false, "1.0", "all");
wp_enqueue_script("rm_script", $file_dir."/includes/admin/rm_script.js", false, "1.0");

}
function mytheme_admin() {

global $themename, $shortname, $options;
$i=0;

if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';

?>
<div class="wrap rm_wrap">
<h2><?php echo $themename; ?> 设置</h2>

<div class="rm_opts">
<form method="post">
<?php foreach ($options as $value) {
switch ( $value['type'] ) {

case "open":
?>

<?php break;

case "close":
?>

</div>
</div>
<br />


<?php break;

case "title":
?>
<p>欢迎你使用 你的企业网站(ndqy.com)为您翻译并改编的主题, 如果你有什么不清楚的地方可以访问我们的网站。</p><p>同时你也可以在<a href="http://ndqy.com/blog/2012/02/18/976.html#5" target="_blank">你的企业网站</a>找到更多的免费主题。</p>


<?php break;

case 'text':
?>

<div class="rm_input rm_text">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
 	<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>" />
 <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>

 </div>
<?php
break;

case 'textarea':
?>

<div class="rm_input rm_textarea">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
 	<textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea>
 <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>

 </div>

<?php
break;

case 'select':
?>

<div class="rm_input rm_select">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>

<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php foreach ($value['options'] as $option) { ?>
		<option <?php if (get_settings( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
</select>

	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
</div>
<?php
break;

case "checkbox":
?>

<div class="rm_input rm_checkbox">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>

<?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />


	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
 </div>
<?php break;
case "section":

$i++;

?>

<div class="rm_section">
<div class="rm_title"><h3><img src="<?php bloginfo('template_directory')?>/includes/admin/images/trans.gif" class="inactive" alt="""><?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save changes" />
</span><div class="clearfix"></div></div>
<div class="rm_options">


<?php break;

}
}
?>

<input type="hidden" name="action" value="save" />
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
 </div>


<?php
}
?>
<?php
add_action('admin_init', 'mytheme_add_init');
add_action('admin_menu', 'mytheme_add_admin');
?>